home *** CD-ROM | disk | FTP | other *** search
- /*
- * Visual Basic Callback Server Source
- *
- * (c) Copyright Microsoft Corp. 1995 All Rights Reserved
- */
-
- #ifdef WIN32
- #ifndef UNICODE
- #include "hostenv.h"
- LPSYSSTR UNICODEtoANSI(BSTR bstrUNICODE)
- {
- unsigned int iLen;
- BSTR bstrANSI = NULL;
- if (bstrUNICODE)
- {
- //iLen = SysStringLen(bstrUNICODE); //Doesn't work with system string.
- if (0 == (iLen = lstrlenW(bstrUNICODE)))
- {
- unsigned short * pStr = bstrUNICODE;
- while (*pStr++);
- iLen = pStr - bstrUNICODE - 1;
- }
- if ( bstrANSI = SysAllocStringByteLen(NULL, iLen) )
- {
- WideCharToMultiByte(CP_ACP, 0, bstrUNICODE, -1, (LPSYSSTR)bstrANSI, iLen + 1, NULL, NULL);
- }
- }
- return (LPSYSSTR) bstrANSI;
- }
- BSTR ANSItoUNICODE(LPSYSSTR bstrANSI)
- {
- unsigned int iLen;
- BSTR bstrUNICODE = NULL;
- if (bstrANSI)
- {
- //iLen = SysStringByteLen((LPOLESTR)bstrANSI);
- iLen = lstrlenA(bstrANSI);
- if ( bstrUNICODE = SysAllocStringLen(NULL, iLen) )
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPSYSSTR)bstrANSI, -1, bstrUNICODE, iLen + 1);
- }
- return bstrUNICODE;
- }
- #endif
- #endif
-